670C - Cinema - CodeForces Solution


implementation sortings *1300

Please click on ads to support us..

C++ Code:

#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
const int maxn = 2e5 + 5;
int n, m;
int a[maxn], b[maxn], c[maxn];
int sum[maxn * 3];
int cnt, mm;
int arr[maxn * 3], num[maxn * 3];
void discrete() {//离散化
    sort(arr + 1, arr + cnt + 1);
    for (int i = 1; i <= cnt; i++) {
        if (i == 1 || arr[i] != arr[i - 1])
            num[++mm] = arr[i];
    }
}
int query(int x) {//二分查找x的位置
    return lower_bound(num + 1, num + mm + 1, x) - num;
}
int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {//将所有电影和人涉及的语言放进一个数组,排序并离散化
        scanf("%d", &a[i]);
        arr[++cnt] = a[i];
    }
    scanf("%d", &m);
    for (int i = 1; i <= m; i++) {
        scanf("%d", &b[i]);
        arr[++cnt] = b[i];
    }
    for (int i = 1; i <= m; i++) {
        scanf("%d", &c[i]);
        arr[++cnt] = c[i];
    }
    discrete();//离散化
    for (int i = 1; i <= n; i++) {
        int id = query(a[i]);//统计每种语言的人的数量
        ++sum[id];
    }
    int bmax = -1, cmax = -1, ans = 0;
    for (int i = 1; i <= m; i++) {//选择满足题目要求的电影
        int x = query(b[i]);
        int y = query(c[i]);
        if (sum[x] > bmax) {//优先考虑让很高兴的人最多
            bmax = sum[x], cmax = sum[y];
            ans = i;
        }
        else {
            if (sum[x] == bmax && sum[y] > cmax) {//如果答案不唯一、则在此前提下再让比较高兴的人最多
                bmax = sum[x], cmax = sum[y];
                ans = i;
            }
        }
    }
    printf("%d\n", ans);
    return 0;
}
  	  				 				 	      			   	 	


Comments

Submit
0 Comments
More Questions

1399A - Remove Smallest
208A - Dubstep
1581A - CQXYM Count Permutations
337A - Puzzles
495A - Digital Counter
796A - Buying A House
67A - Partial Teacher
116A - Tram
1472B - Fair Division
1281C - Cut and Paste
141A - Amusing Joke
112A - Petya and Strings
677A - Vanya and Fence
1621A - Stable Arrangement of Rooks
472A - Design Tutorial Learn from Math
1368A - C+=
450A - Jzzhu and Children
546A - Soldier and Bananas
32B - Borze
1651B - Prove Him Wrong
381A - Sereja and Dima
41A - Translation
1559A - Mocha and Math
832A - Sasha and Sticks
292B - Network Topology
1339A - Filling Diamonds
910A - The Way to Home
617A - Elephant
48A - Rock-paper-scissors
294A - Shaass and Oskols